package com.app.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.app.dao.zl.ZlMapper;
import com.app.domain.TensionCurveData;
import com.app.domain.TensionMainData;
import com.app.domain.TensionProjectInfo;
import com.app.domain.TensionSubData;
import com.app.domain.response.GenericResponse;
import com.app.domain.response.RwdResult;
import com.app.domain.zl.ZljlData;
import com.app.domain.zl.ZljlInfo;
import com.app.domain.zl.ZljlRealData;
import com.app.utils.HttpClients;
import com.app.utils.PhasePairFinder;
import com.app.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DecimalFormat;
import java.util.*;

@Transactional
@Service
@Slf4j
public class UploadService {
    @Autowired
    ZlMapper zlMapper;


    public TensionProjectInfo getTensionProjectInfo(ZljlInfo zljlInfo, List<ZljlData> zljlDataList, String bridge, String shebeibianhao, String selectedRwd, String selectedText) {
        TensionProjectInfo busi_zlxxb = new TensionProjectInfo();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        busi_zlxxb.setSyjid(uuid);
        busi_zlxxb.setShebeibianhao(shebeibianhao);
        if (StringUtils.isNotEmpty(selectedText)) {
            busi_zlxxb.setGjbh(selectedText);
        } else {
            busi_zlxxb.setGjbh(zljlInfo.getQlbh());
        }
        busi_zlxxb.setGcmc("甬台温SHSG04");
        busi_zlxxb.setYzlc("甬台温SHSG04");
        busi_zlxxb.setGjmc(zljlInfo.getQlbh());
        busi_zlxxb.setSgsj(zljlInfo.getZlrq());
        busi_zlxxb.setSnsjqd("C50");
        busi_zlxxb.setSnskqd(bridge);
        busi_zlxxb.setZly1("A1");
        busi_zlxxb.setYbbh1("250410");
        busi_zlxxb.setBdrq1("2025-05-26 08:30:01");
        busi_zlxxb.setZly2("A2");
        busi_zlxxb.setYbbh2("250409");
        busi_zlxxb.setBdrq2("2025-05-26 10:33:01");
        busi_zlxxb.setZlcsu("0");
        busi_zlxxb.setZlcsk("0");
        busi_zlxxb.setZlcsep("0");
        busi_zlxxb.setZlbwpic("0");
        busi_zlxxb.setKualiang("装配式预应力混凝土连续T梁");
        busi_zlxxb.setScljss("");
        busi_zlxxb.setFmqkms("正常");
        busi_zlxxb.setCbunit("ceshi");
        busi_zlxxb.setJlunit("ceshi");
        busi_zlxxb.setHtbh("ceshi-2");
        busi_zlxxb.setMemo("ceshi");
        busi_zlxxb.setStatus("1");
        busi_zlxxb.setMemo("");
        busi_zlxxb.setZlcsu("0");
        busi_zlxxb.setZlcsk("0");
        busi_zlxxb.setZlcsep("0");
        busi_zlxxb.setZlbwpic("");
        busi_zlxxb.setUuid(selectedRwd);
        busi_zlxxb.setIssend("");
        return busi_zlxxb;
    }

    public Map getTensionMainData(ZljlInfo zljlInfo, List<ZljlData> zljlDataList, String syjid, String shebeibianhao, String selectedRwd, String selectedText, List<String> qlbhList) {
        Map<String, List> maps = new HashMap<>();
        List<TensionMainData> tensionMainDataList = new ArrayList<>();
        List<TensionSubData> tensionSubDataList = new ArrayList<>();
        List<TensionCurveData> tensionCurveDataAll = new ArrayList<>();
        List<String> ljdList = new ArrayList<>();
        List<String> ljdList2 = new ArrayList<>();
        for (ZljlData zljlData : zljlDataList) {
            if (zljlData.getDing_xz().equals("B")) {

                PhasePairFinder finder = new PhasePairFinder(qlbhList);
                String known = zljlData.getGsbh();
                if (ljdList2.contains(known)) {
                    continue;
                }
                String paired = finder.findPairedItem(known);
                System.out.println("已知: " + known + " -> 配对: " + (paired != null ? paired : "未找到"));
                if (StringUtils.isNotEmpty(paired)) {
                    //两阶段张拉
                    // 创建一个map，根据最后一位数字分组
                    Map<String, ZljlData> map = new HashMap<>();
                    char lastChar = known.charAt(known.length() - 1);
                    if (lastChar == '1') {
                        map.put("50", zljlData);
                        map.put("100", zlMapper.getZljlDataByQlbhAndGsbh(zljlData.getQlbh(), paired));
                    } else if (lastChar == '2') {
                        map.put("50", zlMapper.getZljlDataByQlbhAndGsbh(zljlData.getQlbh(), paired));
                        map.put("100", zljlData);
                    }
                    TensionMainData tensionMainDataZ = new TensionMainData();
                    String uuidZ = UUID.randomUUID().toString().replace("-", "");
                    tensionMainDataZ.setFguid(uuidZ);
                    tensionMainDataZ.setSyjid(syjid);
                    tensionMainDataZ.setShebeibianhao(shebeibianhao);
                    tensionMainDataZ.setZlsj(zljlInfo.getZlrq());
                    tensionMainDataZ.setGsbh(truncateAtLastDash(known));
                    tensionMainDataZ.setGsgs("6");
                    tensionMainDataZ.setTxml("0");
                    tensionMainDataZ.setSjzll(map.get("100").getZc_sjlz());
                    tensionMainDataZ.setHtl("6.0");
                    tensionMainDataZ.setZscl(getJssczaSpliceZ(map));
                    tensionMainDataZ.setLlscl(map.get("100").getSjscz());
                    tensionMainDataZ.setYxpc("12");
                    tensionMainDataZ.setSclper(getPca(getJssczaSpliceZ(map), map.get("100").getSjscz()));
                    tensionMainDataZ.setWt("正常");
                    tensionMainDataZ.setClqk("正常");
                    tensionMainDataZ.setMemo("");
                    tensionMainDataZ.setHege("合格");
                    tensionMainDataZ.setYzlb("10");
                    tensionMainDataZ.setCzlb("20");
                    tensionMainDataZ.setZzlb("100");
                    tensionMainDataZ.setHoleid(uuidZ); // 孔id
                    tensionMainDataZ.setStatus("1"); // 完成状态
                    tensionMainDataZ.setJlsj(zljlInfo.getZlrq()); // 记录时间
                    tensionMainDataZ.setUuid(selectedRwd); // 张拉任务单号
                    tensionMainDataZ.setIssend(""); // 质监局对接
                    tensionMainDataList.add(tensionMainDataZ);
                    for (int i = 0; i < 6; i++) {
                        tensionSubDataList.add(getTensionSubDataZSplice(map, syjid, uuidZ, i, "1", truncateAtLastDash(known)));
                    }
                    List<ZljlRealData> zljlRealDataList = zlMapper.findRealDataByQlBhAndGsbh(zljlData.getQlbh(), truncateAtLastDash(known) + "%");
                    List<TensionCurveData> tensionCurveDataZ = getTensionCurveData(shebeibianhao, uuidZ, zljlRealDataList, selectedText, "1", truncateAtLastDash(known));
                    tensionCurveDataAll.addAll(tensionCurveDataZ);
                    ljdList2.add(paired);
                } else {
                    String uuid = UUID.randomUUID().toString().replace("-", "");
                    TensionMainData tensionMainData = new TensionMainData();
                    tensionMainData.setFguid(uuid);
                    tensionMainData.setSyjid(syjid);
                    tensionMainData.setShebeibianhao(shebeibianhao);
                    tensionMainData.setZlsj(zljlInfo.getZlrq());
                    tensionMainData.setGsbh(zljlData.getGsbh());
                    tensionMainData.setGsgs("6");
                    tensionMainData.setTxml("0");

                    tensionMainData.setHtl("6.0");
                    if ("0".equals(zljlData.getCc_sjlz().trim())) {
                        tensionMainData.setSjzll(zljlData.getZc_sjlz());
                        tensionMainData.setZscl(getJssczaZ(zljlData));
                        tensionMainData.setSclper(getPca(getJssczaZ(zljlData), zljlData.getSjscz()));
                    } else {
                        tensionMainData.setSjzll(zljlData.getCc_sjlz());
                        tensionMainData.setZscl(getJssczaZcca(zljlData));
                        tensionMainData.setSclper(getPca(getJssczaZcca(zljlData), zljlData.getSjscz()));
                    }
                    tensionMainData.setLlscl(zljlData.getSjscz());
                    tensionMainData.setYxpc("12");
                    tensionMainData.setWt("正常");
                    tensionMainData.setClqk("正常");
                    tensionMainData.setMemo("");
                    tensionMainData.setHege("合格");
                    tensionMainData.setYzlb("10");
                    tensionMainData.setCzlb("20");
                    tensionMainData.setZzlb("100");
                    for (int i = 0; i < 6; i++) {
                        tensionSubDataList.add(getTensionSubData(zljlData, syjid, uuid, i, zljlData.getGsbh(), "1"));
                    }
                    List<ZljlRealData> zljlRealDataList = zlMapper.queryZljlRealData(zljlData.getQlbh(), zljlData.getGsbh());
                    List<TensionCurveData> tensionCurveData = getTensionCurveData(shebeibianhao, uuid, zljlRealDataList, selectedText, "1", zljlData.getGsbh());
                    tensionCurveDataAll.addAll(tensionCurveData);
                    // 设置缺失的属性
                    tensionMainData.setHoleid(uuid); // 孔id
                    tensionMainData.setStatus("1"); // 完成状态
                    tensionMainData.setJlsj(zljlInfo.getZlrq()); // 记录时间
                    tensionMainData.setUuid(selectedRwd); // 张拉任务单号
                    tensionMainData.setIssend(""); // 质监局对接
                    tensionMainDataList.add(tensionMainData);
                }
            } else if (zljlData.getDing_xz().equals("AB")) {
                PhasePairFinder finder = new PhasePairFinder(qlbhList);
                String known = zljlData.getGsbh();
                if (ljdList.contains(known)) {
                    continue;
                }
                String paired = finder.findPairedItem(known);
                System.out.println("已知: " + known + " -> 配对: " + (paired != null ? paired : "未找到"));
                if (StringUtils.isNotEmpty(paired)) {
                    //两阶段张拉
                    // 创建一个map，根据最后一位数字分组
                    Map<String, ZljlData> map = new HashMap<>();
                    char lastChar = known.charAt(known.length() - 1);
                    if (lastChar == '1') {
                        map.put("50", zljlData);
                        map.put("100", zlMapper.getZljlDataByQlbhAndGsbh(zljlData.getQlbh(), paired));
                    } else if (lastChar == '2') {
                        map.put("50", zlMapper.getZljlDataByQlbhAndGsbh(zljlData.getQlbh(), paired));
                        map.put("100", zljlData);
                    }

                    TensionMainData tensionMainDataZ = new TensionMainData();
                    String uuidZ = UUID.randomUUID().toString().replace("-", "");
                    tensionMainDataZ.setFguid(uuidZ);
                    tensionMainDataZ.setSyjid(syjid);
                    tensionMainDataZ.setShebeibianhao(shebeibianhao);
                    tensionMainDataZ.setZlsj(zljlInfo.getZlrq());
                    tensionMainDataZ.setGsbh(truncateAtLastDash(known) + "Z");
                    tensionMainDataZ.setGsgs("6");
                    tensionMainDataZ.setTxml("0");

                    if ("0".equals(map.get("100").getCc_sjlz().trim())) {
                        tensionMainDataZ.setSjzll(map.get("100").getZc_sjlz());
                        tensionMainDataZ.setZscl(getJssczaSpliceZ(map));
                        tensionMainDataZ.setSclper(getPca(getJssczaSpliceZ(map), map.get("100").getSjscz()));
                    } else {
                        tensionMainDataZ.setSjzll(map.get("100").getCc_sjlz());
                        tensionMainDataZ.setZscl(getJssczaSpliceZcca(map));
                        tensionMainDataZ.setSclper(getPca(getJssczaSpliceZcca(map), map.get("100").getSjscz()));
                    }


                    tensionMainDataZ.setHtl("6.0");

                    tensionMainDataZ.setLlscl(map.get("100").getSjscz());
                    tensionMainDataZ.setYxpc("12");

                    tensionMainDataZ.setWt("正常");
                    tensionMainDataZ.setClqk("正常");
                    tensionMainDataZ.setMemo("");
                    tensionMainDataZ.setHege("合格");
                    tensionMainDataZ.setYzlb("10");
                    tensionMainDataZ.setCzlb("20");
                    tensionMainDataZ.setZzlb("100");
                    tensionMainDataZ.setHoleid(uuidZ); // 孔id
                    tensionMainDataZ.setStatus("1"); // 完成状态
                    tensionMainDataZ.setJlsj(zljlInfo.getZlrq()); // 记录时间
                    tensionMainDataZ.setUuid(selectedRwd); // 张拉任务单号
                    tensionMainDataZ.setIssend(""); // 质监局对接

                    TensionMainData tensionMainDataY = new TensionMainData();
                    String uuidY = UUID.randomUUID().toString().replace("-", "");
                    tensionMainDataY.setFguid(uuidY);
                    tensionMainDataY.setSyjid(syjid);
                    tensionMainDataY.setShebeibianhao(shebeibianhao);
                    tensionMainDataY.setZlsj(zljlInfo.getZlrq());
                    tensionMainDataY.setGsbh(truncateAtLastDash(known) + "Y");
                    tensionMainDataY.setGsgs("6");
                    tensionMainDataY.setTxml("0");
                    if ("0".equals(map.get("100").getCc_sjlz().trim())) {
                        tensionMainDataY.setSjzll(map.get("100").getZc_sjlz());
                        tensionMainDataY.setZscl(getJssczaSpliceY(map));
                        tensionMainDataY.setSclper(getPca(getJssczaSpliceY(map), map.get("100").getSjscz()));
                    } else {
                        tensionMainDataY.setSjzll(map.get("100").getCc_sjlz());
                        tensionMainDataY.setZscl(getJssczaSpliceYcca(map));
                        tensionMainDataY.setSclper(getPca(getJssczaSpliceYcca(map), map.get("100").getSjscz()));
                    }
                    tensionMainDataY.setHtl("6.0");
                    tensionMainDataY.setLlscl(map.get("100").getSjscz());
                    tensionMainDataY.setYxpc("12");
                    tensionMainDataY.setWt("正常");
                    tensionMainDataY.setClqk("正常");
                    tensionMainDataY.setMemo("");
                    tensionMainDataY.setHege("合格");
                    tensionMainDataY.setYzlb("10");
                    tensionMainDataY.setCzlb("20");
                    tensionMainDataY.setZzlb("100");
                    tensionMainDataY.setHoleid(uuidY); // 孔id
                    tensionMainDataY.setStatus("1"); // 完成状态
                    tensionMainDataY.setJlsj(zljlInfo.getZlrq()); // 记录时间
                    tensionMainDataY.setUuid(selectedRwd); // 张拉任务单号
                    tensionMainDataY.setIssend(""); // 质监局对接
                    tensionMainDataList.add(tensionMainDataZ);
                    tensionMainDataList.add(tensionMainDataY);

                    for (int i = 0; i < 6; i++) {
                        tensionSubDataList.add(getTensionSubDataZSplice(map, syjid, uuidZ, i, "1", truncateAtLastDash(known) + "Z"));
                        tensionSubDataList.add(getTensionSubDataZSplice(map, syjid, uuidY, i, "2", truncateAtLastDash(known) + "Y"));
                    }
                    List<ZljlRealData> zljlRealDataList = zlMapper.findRealDataByQlBhAndGsbh(zljlData.getQlbh(), truncateAtLastDash(known) + "%");
                    List<TensionCurveData> tensionCurveDataZ = getTensionCurveData(shebeibianhao, uuidZ, zljlRealDataList, selectedText, "1", truncateAtLastDash(known) + "Z");
                    tensionCurveDataAll.addAll(tensionCurveDataZ);

                    List<TensionCurveData> tensionCurveDataY = getTensionCurveData(shebeibianhao, uuidY, zljlRealDataList, selectedText, "2", truncateAtLastDash(known) + "Y");
                    tensionCurveDataAll.addAll(tensionCurveDataY);
                    ljdList.add(paired);

                } else {
                    String uuidZ = UUID.randomUUID().toString().replace("-", "");
                    TensionMainData tensionMainDataZ = new TensionMainData();
                    tensionMainDataZ.setFguid(uuidZ);
                    tensionMainDataZ.setSyjid(syjid);
                    tensionMainDataZ.setShebeibianhao(shebeibianhao);
                    tensionMainDataZ.setZlsj(zljlInfo.getZlrq());
                    tensionMainDataZ.setGsbh(zljlData.getGsbh() + "Z");
                    tensionMainDataZ.setGsgs("6");
                    tensionMainDataZ.setTxml("0");

                    tensionMainDataZ.setHtl("6.0");

                    tensionMainDataZ.setLlscl(zljlData.getSjscz());
                    tensionMainDataZ.setYxpc("12");
                    if ("0".equals(zljlData.getCc_sjlz().trim())) {
                        tensionMainDataZ.setSjzll(zljlData.getZc_sjlz());
                        tensionMainDataZ.setZscl(getJssczaZ(zljlData));
                        tensionMainDataZ.setSclper(getPca(getJssczaZ(zljlData), zljlData.getSjscz()));
                    } else {
                        tensionMainDataZ.setSjzll(zljlData.getCc_sjlz());
                        tensionMainDataZ.setZscl(getJssczaZcca(zljlData));
                        tensionMainDataZ.setSclper(getPca(getJssczaZcca(zljlData), zljlData.getSjscz()));
                    }

                    tensionMainDataZ.setWt("正常");
                    tensionMainDataZ.setClqk("正常");
                    tensionMainDataZ.setMemo("");
                    tensionMainDataZ.setHege("合格");
                    tensionMainDataZ.setYzlb("10");
                    tensionMainDataZ.setCzlb("20");
                    tensionMainDataZ.setZzlb("100");
                    tensionMainDataZ.setHoleid(uuidZ); // 孔id
                    tensionMainDataZ.setStatus("1"); // 完成状态
                    tensionMainDataZ.setJlsj(zljlInfo.getZlrq()); // 记录时间
                    tensionMainDataZ.setUuid(selectedRwd); // 张拉任务单号
                    tensionMainDataZ.setIssend(""); // 质监局对接


                    String uuidY = UUID.randomUUID().toString().replace("-", "");
                    TensionMainData tensionMainDataY = new TensionMainData();
                    tensionMainDataY.setFguid(uuidY);
                    tensionMainDataY.setSyjid(syjid);
                    tensionMainDataY.setShebeibianhao(shebeibianhao);
                    tensionMainDataY.setZlsj(zljlInfo.getZlrq());
                    tensionMainDataY.setGsbh(zljlData.getGsbh() + "Y");
                    tensionMainDataY.setGsgs("6");
                    tensionMainDataY.setTxml("0");

                    tensionMainDataY.setHtl("6.0");

                    if ("0".equals(zljlData.getCc_sjlz().trim())) {
                        tensionMainDataY.setSjzll(zljlData.getZc_sjlz());
                        tensionMainDataY.setZscl(getJssczaY(zljlData));
                        tensionMainDataY.setSclper(getPca(getJssczaY(zljlData), zljlData.getSjscz()));
                    } else {
                        tensionMainDataY.setSjzll(zljlData.getCc_sjlz());
                        tensionMainDataY.setZscl(getJssczaYcca(zljlData));
                        tensionMainDataY.setSclper(getPca(getJssczaYcca(zljlData), zljlData.getSjscz()));
                    }
                    tensionMainDataY.setLlscl(zljlData.getSjscz());
                    tensionMainDataY.setYxpc("12");
                    tensionMainDataY.setWt("正常");
                    tensionMainDataY.setClqk("正常");
                    tensionMainDataY.setMemo("");
                    tensionMainDataY.setHege("合格");
                    tensionMainDataY.setYzlb("10");
                    tensionMainDataY.setCzlb("20");
                    tensionMainDataY.setZzlb("100");
                    tensionMainDataY.setHoleid(uuidY); // 孔id
                    tensionMainDataY.setStatus("1"); // 完成状态
                    tensionMainDataY.setJlsj(zljlInfo.getZlrq()); // 记录时间
                    tensionMainDataY.setUuid(selectedRwd); // 张拉任务单号
                    tensionMainDataY.setIssend(""); // 质监局对接
                    tensionMainDataList.add(tensionMainDataZ);
                    tensionMainDataList.add(tensionMainDataY);
                    for (int i = 0; i < 6; i++) {
                        tensionSubDataList.add(getTensionSubData(zljlData, syjid, uuidZ, i, zljlData.getGsbh() + "Z", "1"));
                        tensionSubDataList.add(getTensionSubData(zljlData, syjid, uuidY, i, zljlData.getGsbh() + "Y", "2"));
                    }
                    List<ZljlRealData> zljlRealDataList = zlMapper.queryZljlRealData(zljlData.getQlbh(), zljlData.getGsbh());
                    List<TensionCurveData> tensionCurveDataZ = getTensionCurveData(shebeibianhao, uuidZ, zljlRealDataList, selectedText, "1", zljlData.getGsbh() + "Z");
                    List<TensionCurveData> tensionCurveDataY = getTensionCurveData(shebeibianhao, uuidY, zljlRealDataList, selectedText, "2", zljlData.getGsbh() + "Y");
                    tensionCurveDataAll.addAll(tensionCurveDataZ);
                    tensionCurveDataAll.addAll(tensionCurveDataY);
                }
            }


        }
        maps.put("tensionMainDataList", tensionMainDataList);
        maps.put("tensionSubDataList", tensionSubDataList);
        maps.put("tensionCurveDataList", tensionCurveDataAll);
        return maps;
    }

    private TensionSubData getTensionSubData(ZljlData zljlData, String syjid, String fguid, int i, String gsbh, String type) {
        TensionSubData busiZlsyS = new TensionSubData();
        String sid = UUID.randomUUID().toString().replace("-", "");
        busiZlsyS.setSid(sid);
        busiZlsyS.setFguid(fguid);
        busiZlsyS.setSyjid(syjid);
        busiZlsyS.setGsbh(gsbh);
        busiZlsyS.setChsj("300");
        busiZlsyS.setStatus("1");
        if (type.equals("1")) {
            if (i == 0) {
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(zljlData.getCsa_zllz1(), "A1"));
                busiZlsyS.setJdzll(zljlData.getCsa_zllz1());
                busiZlsyS.setJdscl(zljlData.getCsa_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getCsa_zllz1());
            } else if (i == 1) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(zljlData.getKza_zllz1(), "A1"));
                busiZlsyS.setJdzll(zljlData.getKza_zllz1());
                busiZlsyS.setJdscl(zljlData.getKza_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getKza_zllz1());
            } else if (i == 2) {//数据源不同
                busiZlsyS.setJdbfb("100");

                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(zljlData.getCc_sjlz().trim())) {
                    busiZlsyS.setYbds(getyy(zljlData.getZca_zllz1(), "A1"));
                    busiZlsyS.setJdzll(zljlData.getZca_zllz1());
                    busiZlsyS.setJdscl(zljlData.getZca_ygsc1());
                    busiZlsyS.setDcscl(getJssczaZX(zljlData));
                } else {
                    busiZlsyS.setYbds(getyy(zljlData.getCca_zllz1(), "A1"));
                    busiZlsyS.setJdzll(zljlData.getCca_zllz1());
                    busiZlsyS.setJdscl(zljlData.getCca_ygsc1());
                    busiZlsyS.setDcscl(getJssczaZXcca(zljlData));
                }
            } else if (i == 3) {//数据源不同
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(zljlData.getCsa_zllz2(), "A2"));
                busiZlsyS.setJdzll(zljlData.getCsa_zllz2());
                busiZlsyS.setJdscl(zljlData.getCsa_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getCsa_zllz2());
            } else if (i == 4) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(zljlData.getKza_zllz2(), "A2"));
                busiZlsyS.setJdzll(zljlData.getKza_zllz2());
                busiZlsyS.setJdscl(zljlData.getKza_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getKza_zllz2());
            } else if (i == 5) {
                busiZlsyS.setJdbfb("100");

                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(zljlData.getCc_sjlz().trim())) {
                    busiZlsyS.setDcscl(getJssczaZY(zljlData));
                    busiZlsyS.setYbds(getyy(zljlData.getZca_zllz2(), "A2"));
                    busiZlsyS.setJdzll(zljlData.getZca_zllz2());
                    busiZlsyS.setJdscl(zljlData.getZca_ygsc2());
                } else {
                    busiZlsyS.setYbds(getyy(zljlData.getCca_zllz2(), "A2"));
                    busiZlsyS.setJdzll(zljlData.getCca_zllz2());
                    busiZlsyS.setJdscl(zljlData.getCca_ygsc2());
                    busiZlsyS.setDcscl(getJssczaZYcca(zljlData));
                }
            }
        } else if (type.equals("2")) {
            if (i == 0) {
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(zljlData.getCsb_zllz1(), "B1"));
                busiZlsyS.setJdzll(zljlData.getCsb_zllz1());
                busiZlsyS.setJdscl(zljlData.getCsb_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getCsb_zllz1());
            } else if (i == 1) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(zljlData.getKzb_zllz1(), "B1"));
                busiZlsyS.setJdzll(zljlData.getKzb_zllz1());
                busiZlsyS.setJdscl(zljlData.getKzb_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getKzb_zllz1());
            } else if (i == 2) {//数据源不同
                busiZlsyS.setJdbfb("100");

                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(zljlData.getCc_sjlz().trim())) {
                    busiZlsyS.setYbds(getyy(zljlData.getZcb_zllz1(), "B1"));
                    busiZlsyS.setJdzll(zljlData.getZcb_zllz1());
                    busiZlsyS.setJdscl(zljlData.getZcb_ygsc1());
                    busiZlsyS.setDcscl(getJssczaYX(zljlData));
                } else {
                    busiZlsyS.setYbds(getyy(zljlData.getCcb_zllz1(), "B1"));
                    busiZlsyS.setJdzll(zljlData.getCcb_zllz1());
                    busiZlsyS.setJdscl(zljlData.getCcb_ygsc1());
                    busiZlsyS.setDcscl(getJssczaYXcca(zljlData));
                }
            } else if (i == 3) {//数据源不同
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(zljlData.getCsb_zllz2(), "B2"));
                busiZlsyS.setJdzll(zljlData.getCsb_zllz2());
                busiZlsyS.setJdscl(zljlData.getCsb_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getCsb_zllz2());
            } else if (i == 4) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(zljlData.getKzb_zllz2(), "B2"));
                busiZlsyS.setJdzll(zljlData.getKzb_zllz2());
                busiZlsyS.setJdscl(zljlData.getKzb_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(zljlData.getKzb_zllz2());
            } else if (i == 5) {
                busiZlsyS.setJdbfb("100");

                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(zljlData.getCc_sjlz().trim())) {
                    busiZlsyS.setYbds(getyy(zljlData.getZcb_zllz2(), "B2"));
                    busiZlsyS.setJdzll(zljlData.getZcb_zllz2());
                    busiZlsyS.setJdscl(zljlData.getZcb_ygsc2());
                    busiZlsyS.setDcscl(getJssczaYY(zljlData));
                } else {
                    busiZlsyS.setYbds(getyy(zljlData.getCcb_zllz2(), "B2"));
                    busiZlsyS.setJdzll(zljlData.getCcb_zllz2());
                    busiZlsyS.setJdscl(zljlData.getCcb_ygsc2());
                    busiZlsyS.setDcscl(getJssczaYYcca(zljlData));
                }
            }
        }
        return busiZlsyS;
    }

    /**
     * \
     * 两阶段
     *
     * @param map
     * @param syjid
     * @param fguid
     * @param i
     * @param type
     * @param gsbh
     * @return
     */
    private TensionSubData getTensionSubDataZSplice(Map<String, ZljlData> map, String syjid, String fguid, int i, String type, String gsbh) {
        TensionSubData busiZlsyS = new TensionSubData();
        String sid = UUID.randomUUID().toString().replace("-", "");
        busiZlsyS.setSid(sid);
        busiZlsyS.setFguid(fguid);
        busiZlsyS.setSyjid(syjid);
        busiZlsyS.setGsbh(gsbh);
        busiZlsyS.setChsj("300");
        busiZlsyS.setStatus("1");
        if (type.equals("1")) {

            if (i == 0) {
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(map.get("50").getCsa_zllz1(), "A1"));
                busiZlsyS.setJdzll(map.get("50").getCsa_zllz1());
                busiZlsyS.setJdscl(map.get("50").getCsa_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getCsa_ygsc1());
            } else if (i == 1) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(map.get("50").getKza_zllz1(), "A1"));
                busiZlsyS.setJdzll(map.get("50").getKza_zllz1());
                busiZlsyS.setJdscl(map.get("50").getKza_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getKza_ygsc1());
            } else if (i == 2) {//数据源不同
                busiZlsyS.setJdbfb("100");

                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(map.get("100").getCc_sjlz().trim())) {
                    busiZlsyS.setDcscl(getJssczaSpliceZX(map));
                    busiZlsyS.setYbds(getyy(map.get("100").getZca_zllz1(), "A1"));
                    busiZlsyS.setJdzll(map.get("100").getZca_zllz1());
                    busiZlsyS.setJdscl(map.get("100").getZca_ygsc1());
                } else {
                    busiZlsyS.setDcscl(getJssczaSpliceZXcca(map));
                    busiZlsyS.setYbds(getyy(map.get("100").getCca_zllz1(), "A1"));
                    busiZlsyS.setJdzll(map.get("100").getCca_zllz1());
                    busiZlsyS.setJdscl(map.get("100").getCca_ygsc1());
                }
            } else if (i == 3) {//数据源不同
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(map.get("50").getCsa_zllz2(), "A2"));
                busiZlsyS.setJdzll(map.get("50").getCsa_zllz2());
                busiZlsyS.setJdscl(map.get("50").getCsa_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getCsa_ygsc2());
            } else if (i == 4) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(map.get("50").getKza_zllz2(), "A2"));
                busiZlsyS.setJdzll(map.get("50").getKza_zllz2());
                busiZlsyS.setJdscl(map.get("50").getKza_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getKza_ygsc2());
            } else if (i == 5) {
                busiZlsyS.setJdbfb("100");
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(map.get("100").getCc_sjlz().trim())) {
                    busiZlsyS.setYbds(getyy(map.get("100").getZca_zllz2(), "A2"));
                    busiZlsyS.setJdzll(map.get("100").getZca_zllz2());
                    busiZlsyS.setJdscl(map.get("100").getZca_ygsc2());
                    busiZlsyS.setDcscl(getJssczaSpliceZY(map));
                } else {
                    busiZlsyS.setYbds(getyy(map.get("100").getCca_zllz2(), "A2"));
                    busiZlsyS.setJdzll(map.get("100").getCca_zllz2());
                    busiZlsyS.setJdscl(map.get("100").getCca_ygsc2());
                    busiZlsyS.setDcscl(getJssczaSpliceZYcca(map));
                }
            }
        } else if (type.equals("2")) {
            if (i == 0) {
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(map.get("50").getCsb_zllz1(), "B1"));
                busiZlsyS.setJdzll(map.get("50").getCsb_zllz1());
                busiZlsyS.setJdscl(map.get("50").getCsb_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getCsb_ygsc1());
            } else if (i == 1) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(map.get("50").getKzb_zllz1(), "B1"));
                busiZlsyS.setJdzll(map.get("50").getKzb_zllz1());
                busiZlsyS.setJdscl(map.get("50").getKzb_ygsc1());
                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getKzb_ygsc1());
            } else if (i == 2) {//数据源不同
                busiZlsyS.setJdbfb("100");

                busiZlsyS.setDh("1");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(map.get("100").getCc_sjlz().trim())) {
                    busiZlsyS.setYbds(getyy(map.get("100").getZcb_zllz1(), "B1"));
                    busiZlsyS.setJdzll(map.get("100").getZcb_zllz1());
                    busiZlsyS.setJdscl(map.get("100").getZcb_ygsc1());
                    busiZlsyS.setDcscl(getJssczaSpliceYX(map));
                } else {
                    busiZlsyS.setYbds(getyy(map.get("100").getCcb_zllz1(), "B1"));
                    busiZlsyS.setJdzll(map.get("100").getCcb_zllz1());
                    busiZlsyS.setJdscl(map.get("100").getCcb_ygsc1());
                    busiZlsyS.setDcscl(getJssczaSpliceYXcca(map));
                }
            } else if (i == 3) {//数据源不同
                busiZlsyS.setJdbfb("10");
                busiZlsyS.setYbds(getyy(map.get("50").getCsb_zllz2(), "B2"));
                busiZlsyS.setJdzll(map.get("50").getCsb_zllz2());
                busiZlsyS.setJdscl(map.get("50").getCsb_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getCsb_ygsc2());
            } else if (i == 4) {
                busiZlsyS.setJdbfb("20");
                busiZlsyS.setYbds(getyy(map.get("50").getKzb_zllz2(), "B2"));
                busiZlsyS.setJdzll(map.get("50").getKzb_zllz2());
                busiZlsyS.setJdscl(map.get("50").getKzb_ygsc2());
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                busiZlsyS.setDcscl(map.get("50").getKzb_ygsc2());
            } else if (i == 5) {
                busiZlsyS.setJdbfb("100");
                busiZlsyS.setDh("2");
                busiZlsyS.setLjhsl("6.0");
                if ("0".equals(map.get("100").getCc_sjlz().trim())) {
                    busiZlsyS.setYbds(getyy(map.get("100").getZcb_zllz2(), "B2"));
                    busiZlsyS.setJdzll(map.get("100").getZcb_zllz2());
                    busiZlsyS.setJdscl(map.get("100").getZcb_ygsc2());
                    busiZlsyS.setDcscl(getJssczaSpliceYY(map));
                } else {
                    busiZlsyS.setYbds(getyy(map.get("100").getCcb_zllz2(), "B2"));
                    busiZlsyS.setJdzll(map.get("100").getCcb_zllz2());
                    busiZlsyS.setJdscl(map.get("100").getCcb_ygsc2());
                    busiZlsyS.setDcscl(getJssczaSpliceYYcca(map));
                }
            }
        }
        return busiZlsyS;
    }


    private List<TensionCurveData> getTensionCurveData(String shebeibianh, String holeId, List<ZljlRealData> zljlRealDataList, String selectedText, String type, String gsbh) {
        List<TensionCurveData> busiZlsySSData = new ArrayList<>();
        for (ZljlRealData zljlRealData : zljlRealDataList) {
            TensionCurveData busiZlsySS = new TensionCurveData();
            if (type.equals("1")) {
                busiZlsySS.setSsid(UUID.randomUUID().toString().replace("-", ""));
                busiZlsySS.setShebeibianhao(shebeibianh);
                busiZlsySS.setJlsj(zljlRealData.getNowdate().split(" ")[0] + " " + zljlRealData.getNowtime().split(" ")[1].substring(0, 8));
                busiZlsySS.setHoleid(holeId);
                busiZlsySS.setZlcs("1");
                busiZlsySS.setZt1("正常");
                busiZlsySS.setZll1(zljlRealData.getA1yl());
                busiZlsySS.setYy1(getyy(zljlRealData.getA1yl(), "A1"));
                busiZlsySS.setDxc1("0");
                busiZlsySS.setScl1(zljlRealData.getA1wy());
                busiZlsySS.setZt2("正常");
                busiZlsySS.setZll2(zljlRealData.getA2yl());
                busiZlsySS.setYy2(getyy(zljlRealData.getA2yl(), "A2"));
                busiZlsySS.setDxc2("0");
                busiZlsySS.setScl2(zljlRealData.getA2wy());
                busiZlsySS.setHolename(gsbh);
                busiZlsySS.setSname(selectedText);
            } else if (type.equals("2")) {
                busiZlsySS.setSsid(UUID.randomUUID().toString().replace("-", ""));
                busiZlsySS.setShebeibianhao(shebeibianh);
                busiZlsySS.setJlsj(zljlRealData.getNowdate().split(" ")[0] + " " + zljlRealData.getNowtime().split(" ")[1].substring(0, 8));
                busiZlsySS.setHoleid(holeId);
                busiZlsySS.setZlcs("1");
                busiZlsySS.setZt1("正常");
                busiZlsySS.setZll1(zljlRealData.getB1yl());
                busiZlsySS.setYy1(getyy(zljlRealData.getB1yl(), "B1"));
                busiZlsySS.setDxc1("0");
                busiZlsySS.setScl1(zljlRealData.getB1wy());
                busiZlsySS.setZt2("正常");
                busiZlsySS.setZll2(zljlRealData.getB2yl());
                busiZlsySS.setYy2(getyy(zljlRealData.getB2yl(), "B2"));
                busiZlsySS.setDxc2("0");
                busiZlsySS.setScl2(zljlRealData.getB2wy());
                busiZlsySS.setHolename(gsbh);
                busiZlsySS.setSname(selectedText);
            }
            busiZlsySSData.add(busiZlsySS);
        }
        return busiZlsySSData;
    }

    /**
     * 截取字符串，去掉最后一个 '-' 及其后面的内容
     */
    public static String truncateAtLastDash(String input) {
        if (input == null || input.isEmpty()) {
            return input;
        }

        int lastDashIndex = input.lastIndexOf('-');
        if (lastDashIndex == -1) {
            return input; // 字符串中没有 '-'，返回原字符串
        }
        return input.substring(0, lastDashIndex); // 截取到 '-' 之前
    }

    private String getTime(ZljlRealData zljlRealData) {
        String s = zljlRealData.getNowtime().split(" ")[1].split("\\.")[0];

        return zljlRealData.getNowdate().split(" ")[0] + " " + s;
    }

    private String getJssczaZX(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getZca_ygsc1()) + Float.parseFloat(zljlData.getKza_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc1())) - 6;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaZY(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getZca_ygsc2()) + Float.parseFloat(zljlData.getKza_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc2())) - 6;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaYX(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getZcb_ygsc1()) + Float.parseFloat(zljlData.getKzb_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc1())) - 6;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaYY(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getZcb_ygsc2()) + Float.parseFloat(zljlData.getKzb_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc2())) - 6;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaZ(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getZca_ygsc1()) + Float.parseFloat(zljlData.getKza_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc1())) +
                (Float.parseFloat(zljlData.getZca_ygsc2()) + Float.parseFloat(zljlData.getKza_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc2())) - 12;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaY(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getZcb_ygsc1()) + Float.parseFloat(zljlData.getKzb_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc1())) +
                (Float.parseFloat(zljlData.getZcb_ygsc2()) + Float.parseFloat(zljlData.getKzb_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc2())) - 12;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }


    private String getJssczaZXcca(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getCca_ygsc1()) + Float.parseFloat(zljlData.getKza_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc1())) - 6;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaZYcca(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getCca_ygsc2()) + Float.parseFloat(zljlData.getKza_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc2())) - 6;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaYXcca(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getCcb_ygsc1()) + Float.parseFloat(zljlData.getKzb_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc1())) - 6;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaYYcca(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getCcb_ygsc2()) + Float.parseFloat(zljlData.getKzb_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc2())) - 6;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaZcca(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getCca_ygsc1()) + Float.parseFloat(zljlData.getKza_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc1())) +
                (Float.parseFloat(zljlData.getCca_ygsc2()) + Float.parseFloat(zljlData.getKza_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsa_ygsc2())) - 12;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaYcca(ZljlData zljlData) {
        //公式
        Float n = (Float.parseFloat(zljlData.getCcb_ygsc1()) + Float.parseFloat(zljlData.getKzb_ygsc1())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc1())) +
                (Float.parseFloat(zljlData.getCcb_ygsc2()) + Float.parseFloat(zljlData.getKzb_ygsc2())) - (2 * Float.parseFloat(zljlData.getCsb_ygsc2())) - 12;

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }


    private String getJssczaSpliceZX(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMga_ygsc1()) + Float.parseFloat(zljlData50.getKza_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc1()) + (Float.parseFloat(zljlData100.getZca_ygsc1()) - Float.parseFloat(zljlData100.getMga_ygsc1())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaSpliceZY(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMga_ygsc2()) + Float.parseFloat(zljlData50.getKza_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc2()) + (Float.parseFloat(zljlData100.getZca_ygsc2()) - Float.parseFloat(zljlData100.getMga_ygsc2())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }


    private String getJssczaSpliceYX(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMgb_ygsc1()) + Float.parseFloat(zljlData50.getKzb_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc1()) + (Float.parseFloat(zljlData100.getZcb_ygsc1()) - Float.parseFloat(zljlData100.getMgb_ygsc1())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaSpliceYY(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMgb_ygsc2()) + Float.parseFloat(zljlData50.getKzb_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc2()) + (Float.parseFloat(zljlData100.getZcb_ygsc2()) - Float.parseFloat(zljlData100.getMgb_ygsc2())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    /**
     * 两阶段左总和
     *
     * @param map
     * @return
     */
    private String getJssczaSpliceZ(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMga_ygsc1()) + Float.parseFloat(zljlData50.getKza_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc1()) + (Float.parseFloat(zljlData100.getZca_ygsc1()) - Float.parseFloat(zljlData100.getMga_ygsc1())) +
                (Float.parseFloat(zljlData50.getMga_ygsc2()) + Float.parseFloat(zljlData50.getKza_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc2()) + (Float.parseFloat(zljlData100.getZca_ygsc2()) - Float.parseFloat(zljlData100.getMga_ygsc2())) - 12;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }


    /**
     * 两阶段右总和
     *
     * @param map
     * @return
     */
    private String getJssczaSpliceY(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMgb_ygsc1()) + Float.parseFloat(zljlData50.getKzb_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc1()) + (Float.parseFloat(zljlData100.getZcb_ygsc1()) - Float.parseFloat(zljlData100.getMgb_ygsc1())) +
                (Float.parseFloat(zljlData50.getMgb_ygsc2()) + Float.parseFloat(zljlData50.getKzb_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc2()) + (Float.parseFloat(zljlData100.getZcb_ygsc2()) - Float.parseFloat(zljlData100.getMgb_ygsc2())) - 12;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }


    private String getJssczaSpliceZXcca(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMga_ygsc1()) + Float.parseFloat(zljlData50.getKza_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc1()) + (Float.parseFloat(zljlData100.getCca_ygsc1()) - Float.parseFloat(zljlData100.getMga_ygsc1())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaSpliceZYcca(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMga_ygsc2()) + Float.parseFloat(zljlData50.getKza_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc2()) + (Float.parseFloat(zljlData100.getCca_ygsc2()) - Float.parseFloat(zljlData100.getMga_ygsc2())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }


    private String getJssczaSpliceYXcca(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMgb_ygsc1()) + Float.parseFloat(zljlData50.getKzb_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc1()) + (Float.parseFloat(zljlData100.getCcb_ygsc1()) - Float.parseFloat(zljlData100.getMgb_ygsc1())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    private String getJssczaSpliceYYcca(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMgb_ygsc2()) + Float.parseFloat(zljlData50.getKzb_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc2()) + (Float.parseFloat(zljlData100.getCcb_ygsc2()) - Float.parseFloat(zljlData100.getMgb_ygsc2())) - 6;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    /**
     * 两阶段左总和
     *
     * @param map
     * @return
     */
    private String getJssczaSpliceZcca(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMga_ygsc1()) + Float.parseFloat(zljlData50.getKza_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc1()) + (Float.parseFloat(zljlData100.getCca_ygsc1()) - Float.parseFloat(zljlData100.getMga_ygsc1())) +
                (Float.parseFloat(zljlData50.getMga_ygsc2()) + Float.parseFloat(zljlData50.getKza_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsa_ygsc2()) + (Float.parseFloat(zljlData100.getCca_ygsc2()) - Float.parseFloat(zljlData100.getMga_ygsc2())) - 12;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }


    /**
     * 两阶段右总和
     *
     * @param map
     * @return
     */
    private String getJssczaSpliceYcca(Map<String, ZljlData> map) {
        ZljlData zljlData50 = map.get("50");
        ZljlData zljlData100 = map.get("100");
        //设置公式
        Float n = (Float.parseFloat(zljlData50.getMgb_ygsc1()) + Float.parseFloat(zljlData50.getKzb_ygsc1())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc1()) + (Float.parseFloat(zljlData100.getCcb_ygsc1()) - Float.parseFloat(zljlData100.getMgb_ygsc1())) +
                (Float.parseFloat(zljlData50.getMgb_ygsc2()) + Float.parseFloat(zljlData50.getKzb_ygsc2())) - 2 * Float.parseFloat(zljlData50.getCsb_ygsc2()) + (Float.parseFloat(zljlData100.getCcb_ygsc2()) - Float.parseFloat(zljlData100.getMgb_ygsc2())) - 12;
        //保留两位小数点
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(n);
    }

    //计算延伸量误差
    private String getPca(String jssczA, String sjsczStr) {
        Float jsscz = Float.parseFloat(jssczA);
        Float sjscz = Float.parseFloat(sjsczStr);
        Float sclperStr = (jsscz - sjscz) / sjscz;
        sclperStr = sclperStr * 100;
        DecimalFormat decimalFormat = new DecimalFormat("0.000");
        return decimalFormat.format(sclperStr);
    }

    //油压回归方程
    public static String getyy(String zll, String dh) {
        float aFloat = Float.parseFloat(zll);
        Float f1 = 0f;
        Float f2 = 0f;

        switch (dh) {
            case "A1":
                f1 = 0.02763f;
                f2 = 0.164f;
                break;
            case "A2":
                f1 = 0.02783f;
                f2 = 0.183f;
                break;
            case "B1":
                f1 = 0.02761f;
                f2 = 0.366f;
                break;
            case "B2":
                f1 = 0.02786f;
                f2 = 0.208f;
                break;
        }
        Float yyf = (f1 * aFloat) + f2;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(yyf);
    }

    public <T> GenericResponse sendMessage(String serviceUrl, String requestJson) throws Exception {
        log.info("requestJson={}", requestJson);
        GenericResponse responseResult = null;
        String result = HttpClients.requestPost(serviceUrl, requestJson);
        log.info("result={}", result);
        responseResult = (GenericResponse) JSONObject.parseObject(StringUtil.replaceBlank(result), GenericResponse.class);

        return responseResult;
    }

    public <T> GenericResponse putMessage(String serviceUrl, String requestJson) throws Exception {
        log.info("requestJson={}", requestJson);
        GenericResponse responseResult = null;
        String result = HttpClients.requestPut(serviceUrl, requestJson);
        log.info("result={}", result);
        responseResult = (GenericResponse) JSONObject.parseObject(StringUtil.replaceBlank(result), GenericResponse.class);

        return responseResult;
    }

    public Map<String, String> getRwdlist(String rwdService, String shebeibianhao) throws Exception {
        Map<String, Object> requestMap = new HashMap();
        Map<String, String> resultMap = new HashMap<>();
        requestMap.put("shebeibianh", shebeibianhao);
        GenericResponse<List<RwdResult>> responseResult = null;
        String result = HttpClients.doPost(rwdService, requestMap);
        log.info("result={}", result);
        responseResult = JSON.parseObject(StringUtil.replaceBlank(result), new TypeReference<GenericResponse<List<RwdResult>>>() {
        });
        log.info("responseResult={}", responseResult);
        if (responseResult.getSuccess()) {
            List<RwdResult> rwdResultList = responseResult.getResult();
            // 遍历 rwdResultList，将 status 为 "0" 的对象以 sgbwname 为 key、uuid 为 value 存入 resultMap 中
            if (rwdResultList != null) {
                for (RwdResult rwdResult : rwdResultList) {
                    if ("0".equals(rwdResult.getStatus2())||"0".equals(rwdResult.getStatus())||"0".equals(rwdResult.getWcstatus())) {
                        resultMap.put(rwdResult.getSgbwname(), rwdResult.getUuid());
                    }
                }
            }
        }
        return resultMap;
    }
}
